<template>
  <view class="normal-login-container">
    <view class="logo-content align-center justify-center flex">
      <text class="title">静善集运小程序</text>
    </view>
    <view class="login-form-content">
      <view class="action-btn">
        <button open-type="getUserInfo" @click="wxLogin" class="login-btn cu-btn block bg-blue lg round">授权登录</button>
      </view>
	  <view class="action-btn1">
		  <button @click="cancel" class="login-btn cu-btn block bg-gray lg round">取消授权</button>
	  </view>
      <view class="xieyi text-center">
        <text class="text-grey1">登录即代表同意</text>
        <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
        <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
      </view>
    </view>
     
  </view>
</template>

<script>
	import {login} from '@/api/login.js';
  export default {
    data() {
      return {
		loginForm:{
			code:""
		}
      }
    },
    created() {
    },
    methods: {
	  //授权登录
	  wxLogin(){
		uni.showLoading({
		  title:'登录中',
		  });
		  uni.getUserProfile({
		  	desc:'登录的数据',
			success:(users)=>{
				console.log(users,'返回的用户信息');
				 uni.login({
					success:(lres)=>{
						console.log(lres,'请求微信登录返回数据,获得code');
						// //调取后端接口返回状态码，判断当前登录用户是否注册
						this.loginForm.code=lres.code;
						login(this.loginForm).then(res=>{
							console.log(res,'微信一键登录返回的数据')
							if(res.code==200){
								uni.setStorageSync('App-Token',res.token);
							this.$tab.reLaunch('/pages/mine/index');
							}						
						})
					}
				})
			}
		  })
	  },
      // 隐私协议 
      handlePrivacy() {
        let site = this.globalConfig.appInfo.agreements[0]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
      // 用户协议
      handleUserAgrement() {
        let site = this.globalConfig.appInfo.agreements[1]
        this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
      },
	  //取消授权
     cancel(){
		this.$tab.reLaunch('/pages/mine/index')
	 },
      // 登录成功后，处理函数
      // loginSuccess(result) {
      //   // 设置用户信息
      //   this.$store.dispatch('GetInfo').then(res => {
      //     this.$tab.reLaunch('/pages/index')
      //   })
      // }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }

  .normal-login-container {
    width: 100%;

    .logo-content {
      width: 100%;
      font-size: 21px;
      text-align: center;
      padding-top: 15%;

      image {
        border-radius: 4px;
      }
      .title {
        margin-left: 10px;
      }
    }   
	 .action-btn{
	 	width: 600rpx;
	 	margin: auto;
		font-size: 25px;
		margin-top: 40rpx;
	 }
	 .action-btn1{
	 	width: 600rpx;
	 	margin: auto;
	 	font-size: 25px;
	 	margin-top: 10rpx;	  
	 	  }
      .reg {
        margin-top: 15px;
      }
      .xieyi {
        color: #333;
        margin-top: 20px;
      }
    }

</style>
